// index.js
const util = require("../../util.js");
const base = require("../../util.js")
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cardCur: 0,
    page_direction: '',
    platform: "",
    checkLang: Boolean,
    RootUrl: app.globalData.RootUrl,
    swp: 3,
    userInfo: '',
    swiperList: [{
      id: 0,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84000.jpg'
    }, {
      id: 1,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big84001.jpg',
    }, {
      id: 2,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big39000.jpg'
    }, {
      id: 3,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big10001.jpg'
    }, {
      id: 4,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big25011.jpg'
    }, {
      id: 5,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big21016.jpg'
    }, {
      id: 6,
      type: 'image',
      url: 'https://ossweb-img.qq.com/images/lol/web201310/skin/big99008.jpg'
    }],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let checkLang = wx.getStorageSync('language');
    let open_id = wx.getStorageSync('userInfo'.openid);
    if (checkLang == "uy") {
      this.setData({
        checkLang: true,
        platform: app.globalData.platform,
      })
    }
    // this.Choose_lang();
    this.setData({
      $t: base._t(),
      CustomBar: app.globalData.CustomBar,
    })
    if (open_id) {
      this.setData({
        userInfo: wx.getStorageSync('userInfo'),
      })
    } else {
      this.getIndexInfo();
    }
  },

  changeswiper(e) {
    this.setData({
      swp: e.currentTarget.dataset.swp,
    })
  },
  swiperchange(e) {
    this.setData({
      current: e.detail.current,
      swp: e.detail.current,
    })
  },


  //语言选择函数
  Choose_lang() {
    let lang = wx.getStorageSync('language');
    if (lang == 'zh') {
      wx.setStorageSync('language', 'uy');
    } else {
      wx.setStorageSync('language', 'zh');
    }
    let lang1 = wx.getStorageSync('language');
    if (lang1 == "uy") {
      this.setData({
        page_direction: 'rtl'
      })
    } else {
      this.setData({
        page_direction: 'ltr'
      })
    }
    this.setData({
      $t: base._t(),
      lang1: lang1,
    })
    this.onLoad();
  },

  tosreach(e) {
    console.log(e);
    wx.navigateTo({
      url: "/pages/sreach/sreach",
    });
  },
  getIndexInfo() {
    let that = this;
    wx.request({
      url: app.globalData.RequestUrl + 'appIndex',
      method: "POST",
      data: "",
      success(res) {
        console.log(res);
        that.setData({
          indexInfo: res.data.data
        });
      }
    })
  },



  tovip() {
    wx.navigateTo({
      url: '../vip/vip',
    })
  },

  userlogin() {
    let that = this;
    wx.getUserProfile({
      desc: '用于完善会员资料',
      success(res) {
        wx.login({
          success(res1) {
            // console.log(res1);
            wx.request({
              url: app.globalData.RequestUrl + 'wxuserLogin',
              method: "POST",
              data: {
                "code": res1.code,
                "userInfo": res.userInfo
              },
              success(res) {
                wx.setStorageSync('userInfo', res.data.userInfo)
                that.setData({
                  userInfo: res.data.userInfo,
                })
              }
            })
          }
        })
      }
    })
  },



  toCourseList(e) {
    let that = this;
    let menuId = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/pages/couseList/courseList?menuId=' + menuId,
    })
  },
})